﻿using CommandProcessor.Command;
using Data.Infrastructure;
using Data.Models;
using Data.Repositories;
using Domain.Commands;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Domain.Handlers
{
    public class CreateOrUpdateCurrencyHandler : ICommandHandler<CreateOrUpdateCurrencyCommand>
    {
        private readonly ICurrencyRepository currencyRepository;
        private readonly IUnitOfWork unitOfWork;
        public CreateOrUpdateCurrencyHandler(ICurrencyRepository currencyRepository, IUnitOfWork unitOfWork)
        {
            this.currencyRepository = currencyRepository;
            this.unitOfWork = unitOfWork;
        }
        public ICommandResult Execute(CreateOrUpdateCurrencyCommand command)
        {
            var currency = new Currency
            {
                ID = command.ID,
                Code = command.Code,
                Descripttion=command.Descripttion,
                ForeignExchange=command.ForeignExchange,
                HomeExchange=command.HomeExchange,
                IsDefault=command.IsDefault,
                Name=command.Name,
                Status=command.Status,
                Symbol=command.Symbol,
                UOMID=command.UOMID
                
            };
            if (currency.ID == 0)
                currencyRepository.Add(currency);
            else
                currencyRepository.Update(currency);

            unitOfWork.Commit();
            return new CommandResult(true);
        }
        public ICommandResult ExecuteRange(IEnumerable<CreateOrUpdateCurrencyCommand> commands)
        {
            throw new NotImplementedException();
        }
        public ICommandResult DeleteRange(IEnumerable<CreateOrUpdateCurrencyCommand> commands)
        {
            throw new NotImplementedException();
        }
    }
}
